<?php
/*
 * The MIT License
 * 
 * Copyright (c) 2009 David Neu
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

if ($_GET['lang'] != 'de') {
    setlocale(LC_ALL, 'en_EN');
    putenv ("LANG=en_EN"); 
} else {
    setlocale(LC_ALL, 'de_DE');
    putenv ("LANG=de_DE");
}

bindtextdomain("GPXFlash", "./locale");
textdomain("GPXFlash");

require_once('GpxIndex.php');

$index = new GpxIndex('.');
$data = $index->createIndex();

include('header.html');
?>
<h1><?php echo _('headline');?></h1>
<p><?php echo _('intro');?></p>
<table>
<tr>
    <th><?php echo _('Dateiname');?></th>
    <th><?php echo _('Datum');?></th>
    <th><?php echo _('Tracks');?></th>
    <th><?php echo _('Waypoints');?></th>
    <th><?php echo _('Trackpoints');?></th>
</tr>
<?php
foreach ($data as $file) {
    if (!strpos($class,'alt')) {
        $class = ' class="alt';
    } else {
        $class = ' class="';
    }
    echo '<tr>';
        echo '<td'.$class.'"><a href="gpxflash.php?file='.$file->getFilename().'">'.$file->getFilename().'</a></td>';
        echo '<td'.$class.'">'.date(_('d.m.Y H:i:s'),$file->getFirstTime()).'</td>';
        echo '<td'.$class.'">';
        foreach ($file->getTrackNames() as $track) {
            echo $track.'<br/>';
        }
        echo '</td>';
        echo '<td'.$class.' number">'.$file->getTrackpointCount().'</td>';
        echo '<td'.$class.' number">'.$file->getWaypointCount().'</td>';
    echo '</tr>';
}
?>
</table>
</body>
</html>